# import numpy as np
#
# a = np.arange(9).reshape(3, 3)
# print('原始数组：')
# for row in a:
#     print(row)
#
# # 对数组中每个元素都进行处理，可以使用flat属性，该属性是一个数组元素迭代器：
# print('迭代后的数组：')
# for element in a.flat:
#     print(element, end = " ")
#
# print()
#
# # 返回的是一个copy，不影响原数组
# print(a.flatten())
# # 返回的是一个view（视图），可能改变原数组
# print(a.ravel(order='F'))

# 高级迭代器
# for num in np.nditer(a, flags=['external_loop']):
#     print(num, end = " ")
#
# print()
#
# for num in np.nditer(a):
#     print(num, end = " ")



# import numpy as np
#
# x = np.arange(9).reshape(1, 3, 3)
#
# print('数组 x：')
# print(x)
# print('\n')
# # 降维
# y = np.squeeze(x)
#
# print('数组 y：')
# print(y)
# print('\n')
#
# print('数组 x 和 y 的形状：')
# print(x.shape, y.shape)


# import numpy as np
# 水平堆叠：np.concatenate((a, b), axis=1) == np.hstack((a, b))
# 垂直堆叠：np.concatenate((a, b), axis=0) == np.vstack((a, b))

# a = np.array([[1, 2], [3, 4]])
# b = np.array([[4, 5], [6, 7]])
# print(np.concatenate((a, b), axis=0))
# print(np.concatenate((a, b), axis=1))
# print(np.stack((a, b), axis=0))
# print(np.stack((a, b), axis=1))
# print(np.hstack((a, b)))
# print(np.vstack((a, b)))
#
# c = np.arange(9)
# print(np.split(c, 3))
# print(np.split(c, [4, 7])) # 0 1 2 3    4 5 6   7 8

# 和v(h)stack相反
# np.split(d, 2, axis=1) == np.hsplit(d, 2)
# np.split(d, 2, axis=0) == np.vsplit(d, 2)

# d = np.arange(16).reshape(4, 4)
# print(np.split(d, 2))
# print(np.split(d, 2, axis=1))
# print(np.hsplit(d, 2))
# print(np.vsplit(d, 2))

# import numpy as np
# a = np.arange(1, 7).reshape((2, 3))
# print(a)
# print(np.resize(a, (3, 2)))
# print(np.append(a, [7, 8, 9]))
# # print(np.append(a, [[7, 8, 9]], axis=0))
# print(np.append(a, [[0, 0, 0],[0, 0, 0]], axis=1))

# a = np.array([[1, 2], [3, 4], [5, 6]])
#
# print('未传递 Axis 参数。 在删除之前输入数组会被展开。')
# print(np.insert(a, 3, [11, 12]))
# print('\n')
# print('传递了 Axis 参数。 会广播值数组来配输入数组。')
#
# print('沿轴 0 广播：')
# print(np.insert(a, 1, [11], axis=0))
# print('\n')
#
# print('沿轴 1 广播：')
# print(np.insert(a, 1, 11, axis=1))

# import numpy as np
#
# a = np.arange(12).reshape(3, 4)
#
# print('第一个数组：')
# print(a)
# print('\n')
#
# print('未传递 Axis 参数。 在插入之前输入数组会被展开。')
# print(np.delete(a, 5))
# print('\n')
#
# print('删除第二列行：')
# print(np.delete(a, 1, axis=1))
# print(np.delete(a, 1, axis=0))
# print('\n')

# import numpy as np
#
# a = np.array([5, 2, 6, 2, 7, 5, 6, 8, 2, 9])
#
# print('第一个数组：')
# print(a)
# print('\n')
#
# print('第一个数组的去重值：')
# u = np.unique(a)
# print(u)
# print('\n')
#
# print('去重数组的索引数组：')
# u, indices = np.unique(a, return_index=True)
# print(indices)
# print('\n')
#
# print('我们可以看到每个和原数组下标对应的数值：')
# print(a)
# print('\n')
#
# print('去重数组的下标：')
# u, indices = np.unique(a, return_inverse=True)
# print(u)
# print('\n')
#
# print('下标为：')
# print(indices)
# print('\n')
#
# print('使用下标重构原数组：')
# print(u[indices])
# print('\n')
#
# print('返回去重元素的重复数量：')
# u, indices = np.unique(a, return_counts=True)
# print(u)
# print(indices)

import numpy as np
a = np.array([1, 2, 2, 3, 3, 5, 4, 6 ,5 ,4, 6])
print(np.unique(a, return_counts=True))